#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column

from backend.app.core.models.base import Base, id_key


class InstanceSchema(Base):
    """系统api"""

    __tablename__ = 'dbms_instance_schema'

    id: Mapped[id_key] = mapped_column(init=False)
    prefix_name: Mapped[str] = mapped_column(String(50), unique=True, comment='tag名称')
    cnt: Mapped[int] = mapped_column(default=1, comment='角色状态（0停用 1正常）')
    step_cnt: Mapped[int] = mapped_column(default=0, comment='角色状态（0停用 1正常）')
    schema_type: Mapped[int] = mapped_column(default=1, comment='数据库类型1单库2从0开始3从0开始并补位4根据内容分隔符')
    db_context: Mapped[str] = mapped_column(String(50), unique=True, comment='1单库2从0开始3从0开始并补位4根据内容分隔符')
    db_name: Mapped[str] = mapped_column(String(50), unique=True, comment='tag代码')
    remark: Mapped[str | None] = mapped_column(String(255), comment='备注')
    instance_id: Mapped[int | None] = mapped_column(
        ForeignKey('dbms_instance.id', ondelete='SET NULL'), default=None, comment='实例关联ID'
    )
    instance: Mapped[Union['instance', None]] = relationship(init=False, back_populates='instanceschemas')

